package com.zhida.smartcontrol.knet;

import com.jay.tools.utils.LogUtil;
import com.yanzhenjie.kalle.Request;
import com.yanzhenjie.kalle.Response;
import com.yanzhenjie.kalle.connect.Interceptor;
import com.yanzhenjie.kalle.connect.http.Chain;

import java.io.IOException;

/**
 * author: tanjianpei
 * date: 2019/9/16 016 11:00
 * description: 自定义日志输出
 */
public class LogInterceptor implements Interceptor {
    private final String mTag;
    private final boolean isEnable;

    public LogInterceptor(String mTag, boolean isEnable) {
        this.mTag = mTag;
        this.isEnable = isEnable;
    }

    @Override
    public Response intercept(Chain chain) throws IOException {
        Request request = chain.request();
        if (isEnable) {
            Response response = chain.proceed(request);

            String url = request.url().toString();
            LogUtil.e(mTag, "请求地址：" + url);

            return response;
        }

        return chain.proceed(request);
    }
}
